local M = require "packages/mamashengde/record/Made"

local moli = fk.CreateSkill {
  name = "ruiji__moli",
  tags = { M.HenshinSkill },
}

Fk:loadTranslationTable {
  ["ruiji__moli"] = "魔力",
  [":ruiji__moli"] = "<a href='#made_henshin_skill'><font color='pink'>变身技</font></a>（0/5），游戏开始时或当你造成或受到伤害时，你获得1点魔力；"..
  "当你进入濒死状态时或发动“铃音”后，你<a href='ruiji__Henshin'><font color='pink'>进行吟唱并变身</font></a>。",
  ["ruiji__Henshin"] = "在对应的时机点，若你的魔力已达上限，你可以吟唱咒语并变身为闪耀战姬！<br>" ..
  "<b>圣裁</b>：出牌阶段，你可消耗任意魔力，将等量张手牌当做无距离次数限制的【杀】使用，" ..
  "你以此法使用的【杀】造成的伤害+X（X为你本次消耗的魔力数）。<br>" ..
  "<b>光辉</b>：锁定技，所有进入变身状态的角色使用牌不能被非变身状态的角色响应；称号与你相同的角色造成伤害时，你获得1点魔力。",

  ["$ruiji__moli1"] = "一天是哥布林，一辈子都是哥布林！", -- 吟唱
  ["$ruiji__moli2"] = "一天是哥布林，一辈子都是哥布林！",
}

local spec = {
  mute = true,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    M.changeMaryoku(player, 1, moli.name)
  end,
}

moli:addEffect(fk.GameStart, spec)
moli:addEffect(fk.DetermineDamageCaused, spec)
moli:addEffect(fk.DetermineDamageInflicted, spec)

moli:addEffect(fk.EnterDying, {
  anim_type = "big",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(moli.name) and
      M.getMaryoku(player) >= M.getMaryokuMax(player) and player.general == "shine__ruiji"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local target_general = "shine2__ruiji" -- 目标武将
    if M.enterHenshin(player, target_general, moli.name) then
        -- 变身成功后的处理
        room:notifySkillInvoked(player, moli.name, "positive")
    end
  end,
})

moli:addEffect(fk.AfterCardsMove, {
  anim_type = "big",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(moli.name) and
    M.getMaryoku(player) >= M.getMaryokuMax(player) and
    player.general == "shine__ruiji"then
      for _, move in ipairs(data) do
        if move.from == player then
          for _, info in ipairs(move.moveInfo) do
            if info.fromSpecialName == "ruiji_wang" then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local target_general = "shine2__ruiji" -- 目标武将
    if M.enterHenshin(player, target_general, moli.name) then
        -- 变身成功后的处理
        room:notifySkillInvoked(player, moli.name, "positive")
    end
  end,
})

moli:addEffect(fk.AfterSkillEffect, {
  anim_type = "big",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(moli.name) and data.skill.name == "lingyin" and
      M.getMaryoku(player) >= M.getMaryokuMax(player) and player.general == "shine__ruiji"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local target_general = "shine2__ruiji" -- 目标武将
    if M.enterHenshin(player, target_general, moli.name) then
        -- 变身成功后的处理
        room:notifySkillInvoked(player, moli.name, "positive")
    end
  end,
})

moli:addAcquireEffect(function (self, player)
  if M.getMaryokuMax(player) == 0 then
    M.setMaryokuMax(player, 5, moli.name)
  end
end)

return moli